var Markdown;
Markdown = typeof exports === "object" && typeof require === "function" ? exports: {}; (function() {
    function y(j) {
        return j
    }
    function C() {
        return ! 1
    }
    function t() {}
    function o() {}
    t.prototype = {
        chain: function(j, v) {
            var o = this[j];
            if (!o) throw Error("unknown hook " + j);
            this[j] = o === y ? v: function(j) {
                return v(o(j))
            }
        },
        set: function(j, o) {
            if (!this[j]) throw Error("unknown hook " + j);
            this[j] = o
        },
        addNoop: function(j) {
            this[j] = y
        },
        addFalse: function(j) {
            this[j] = C
        }
    };
    Markdown.HookCollection = t;
    o.prototype = {
        set: function(j, o) {
            this["s_" + j] = o
        },
        get: function(j) {
            return this["s_" + j]
        }
    };
    Markdown.Converter = function() {
        function j(a) {
            return a = a.replace(/^[ ]{0,3}\[(.+)\]:[ \t]*\n?[ \t]*<?(\S+?)>?(?=\s|$)[ \t]*\n?[ \t]*((\n*)["(](.+?)[")][ \t]*)?(?:\n+)/gm,
            function(a, m, c, b, d, e) {
                m = m.toLowerCase();
                q.set(m, g(c));
                if (d) return b;
                else e && D.set(m, e.replace(/"/g, "&quot;"));
                return ""
            })
        }
        function v(a) {
            a = a.replace(/^(<(p|div|h[1-6]|blockquote|pre|table|dl|ol|ul|script|noscript|form|fieldset|iframe|math|ins|del)\b[^\r]*?\n<\/\2>[ \t]*(?=\n+))/gm, z);
            a = a.replace(/^(<(p|div|h[1-6]|blockquote|pre|table|dl|ol|ul|script|noscript|form|fieldset|iframe|math)\b[^\r]*?.*<\/\2>[ \t]*(?=\n+)\n)/gm, z);
            a = a.replace(/\n[ ]{0,3}((<(hr)\b([^<>])*?\/?>)[ \t]*(?=\n{2,}))/g, z);
            a = a.replace(/\n\n[ ]{0,3}(<!(--(?:|(?:[^>-]|-[^>])(?:[^-]|-[^-])*)--)>[ \t]*(?=\n{2,}))/g, z);
            return a = a.replace(/(?:\n\n)([ ]{0,3}(?:<([?%])[^\r]*?\2>)[ \t]*(?=\n{2,}))/g, z)
        }
        function z(a, c) {
            var b;
            b = c.replace(/^\n+/, "");
            b = b.replace(/\n+$/g, "");
            return b = "\n\n~K" + (H.push(b) - 1) + "K\n\n"
        }
        function A(a, c) {
            a = x(a);
            a = a.replace(/^[ ]{0,2}([ ]?\*[ ]?){3,}[ \t]*$/gm, "<hr />\n");
            a = a.replace(/^[ ]{0,2}([ ]?-[ ]?){3,}[ \t]*$/gm, "<hr />\n");
            a = a.replace(/^[ ]{0,2}([ ]?_[ ]?){3,}[ \t]*$/gm, "<hr />\n");
            a = F(a);
            a = y(a);
            a = d(a);
            a = v(a);
            return a = b(a, c)
        }
        function e(m) {
            m = a(m);
            m = B(m);
            m = m.replace(/\\(\\)/g, l);
            m = m.replace(/\\([`*_{}\[\]()>#+-.!])/g, l);
            m = m.replace(/(!\[(.*?)\][ ]?(?:\n[ ]*)?\[(.*?)\])()()()()/g, r);
            m = m.replace(/(!\[(.*?)\]\s?\([ \t]*()<?(\S+?)>?[ \t]*((['"])(.*?)\6[ \t]*)?\))/g, r);
            m = m.replace(/(\[((?:\[[^\]]*\]|[^\[\]])*)\][ ]?(?:\n[ ]*)?\[(.*?)\])()()()()/g, E);
            m = m.replace(/(\[((?:\[[^\]]*\]|[^\[\]])*)\]\([ \t]*()<?((?:\([^)]*\)|[^()\s])*?)>?[ \t]*((['"])(.*?)\6[ \t]*)?\))/g, E);
            m = m.replace(/(\[([^\[\]]+)\])()()()()()/g, E);
            m = k(m);
            m = m.replace(/~P/g, "://");
            m = g(m);
            m = m.replace(/([\W_]|^)(\*\*|__)(?=\S)([^\r]*?\S[\*_]*)\2([\W_]|$)/g, "$1<strong>$3</strong>$4");
            m = m.replace(/([\W_]|^)(\*|_)(?=\S)([^\r\*_]*?\S)\2([\W_]|$)/g, "$1<em>$3</em>$4");
            return m = m.replace(/  +\n/g, " <br>\n")
        }
        function B(a) {
            return a = a.replace(/(<[a-z\/!$]("[^"]*"|'[^']*'|[^'">])*>|<!(--(?:|(?:[^>-]|-[^>])(?:[^-]|-[^-])*)--)>)/gi,
            function(a) {
                var m = a.replace(/(.)<\/?code>(?=.)/g, "$1`");
                return m = p(m, a.charAt(1) == "!" ? "\\`*_/": "\\`*_")
            })
        }
        function E(a, c, b, d, g, e, k, f) {
            f == void 0 && (f = "");
            a = b.replace(/:\/\//g, "~P");
            d = d.toLowerCase();
            if (g == "") if (d == "" && (d = a.toLowerCase().replace(/ ?\n/g, " ")), q.get(d) != void 0) g = q.get(d),
            D.get(d) != void 0 && (f = D.get(d));
            else if (c.search(/\(\s*\)$/m) > -1) g = "";
            else return c;
            g = i(g);
            g = p(g, "*_");
            c = '<a href="' + g + '"';
            f != "" && (f = h(f), f = p(f, "*_"), c += ' title="' + f + '"');
            c += ">" + a + "</a>";
            return c
        }
        function h(a) {
            return a.replace(/>/g, "&gt;").replace(/</g, "&lt;").replace(/"/g, "&quot;")
        }
        function r(a, c, b, d, g, e, f, i) {
            a = b;
            d = d.toLowerCase();
            i || (i = "");
            if (g == "") if (d == "" && (d = a.toLowerCase().replace(/ ?\n/g, " ")), q.get(d) != void 0) g = q.get(d),
            D.get(d) != void 0 && (i = D.get(d));
            else return c;
            a = p(h(a), "*_[]()");
            g = p(g, "*_");
            c = '<img src="' + g + '" alt="' + a + '"';
            i = h(i);
            i = p(i, "*_");
            c += ' title="' + i + '"';
            c += " />";
            return c
        }
        function x(a) {
            a = a.replace(/^(.+)[ \t]*\n=+[ \t]*\n+/gm,
            function(a, c) {
                return "<h1>" + e(c) + "</h1>\n\n"
            });
            a = a.replace(/^(.+)[ \t]*\n-+[ \t]*\n+/gm,
            function(a, c) {
                return "<h2>" + e(c) + "</h2>\n\n"
            });
            return a = a.replace(/^(\#{1,6})[ \t]*(.+?)[ \t]*\#*\n+/gm,
            function(a, c, b) {
                a = c.length;
                return "<h" + a + ">" + e(b) + "</h" + a + ">\n\n"
            })
        }
        function F(a) {
            a += "~0";
            var c = /^(([ ]{0,3}([*+-]|\d+[.])[ \t]+)[^\r]+?(~0|\n{2,}(?=\S)(?![ \t]*(?:[*+-]|\d+[.])[ \t]+)))/gm;
            I ? a = a.replace(c,
            function(a, c, b) {
                a = b.search(/[*+-]/g) > -1 ? "ul": "ol";
                c = w(c, a);
                c = c.replace(/\s+$/, "");
                return "<" + a + ">" + c + "</" + a + ">\n"
            }) : (c = /(\n\n|^\n?)(([ ]{0,3}([*+-]|\d+[.])[ \t]+)[^\r]+?(~0|\n{2,}(?=\S)(?![ \t]*(?:[*+-]|\d+[.])[ \t]+)))/g, a = a.replace(c,
            function(a, c, b, d) {
                a = d.search(/[*+-]/g) > -1 ? "ul": "ol";
                b = w(b, a);
                return c + "<" + a + ">\n" + b + "</" + a + ">\n"
            }));
            return a = a.replace(/~0/, "")
        }
        function w(a, c) {
            I++;
            a = a.replace(/\n{2,}$/, "\n");
            a += "~0";
            var b = K[c],
            d = !1,
            a = a.replace(RegExp("(^[ \\t]*)(" + b + ")[ \\t]+([^\\r]+?(\\n+))(?=(~0|\\1(" + b + ")[ \\t]+))", "gm"),
            function(a, c, b, m) {
                a = m; (c = /\n\n$/.test(a)) || a.search(/\n{2,}/) > -1 || d ? a = A(u(a), !0) : (a = F(u(a)), a = a.replace(/\n$/, ""), a = e(a));
                d = c;
                return "<li>" + a + "</li>\n"
            }),
            a = a.replace(/~0/g, "");
            I--;
            return a
        }
        function y(a) {
            a += "~0";
            a = a.replace(/(?:\n\n|^)((?:(?:[ ]{4}|\t).*\n+)+)(\n*[ ]{0,3}[^ \t\n]|(?=~0))/g,
            function(a, b, d) {
                a = c(u(b));
                a = n(a);
                a = a.replace(/^\n+/g, "");
                a = a.replace(/\n+$/g, "");
                return "\n\n" + ("<pre><code>" + a + "\n</code></pre>") + "\n\n" + d
            });
            return a = a.replace(/~0/, "")
        }
        function s(a) {
            a = a.replace(/(^\n+|\n+$)/g, "");
            return "\n\n~K" + (H.push(a) - 1) + "K\n\n"
        }
        function a(a) {
            return a = a.replace(/(^|[^\\])(`+)([^\r]*?[^`])\2(?!`)/gm,
            function(a, b, d, g) {
                a = g.replace(/^([ \t]*)/g, "");
                a = a.replace(/[ \t]*$/g, "");
                a = c(a);
                a = a.replace(/:\/\//g, "~P");
                return b + "<code>" + a + "</code>"
            })
        }
        function c(a) {
            a = a.replace(/&/g, "&amp;");
            a = a.replace(/</g, "&lt;");
            a = a.replace(/>/g, "&gt;");
            return a = p(a, "*_{}[]\\", !1)
        }
        function d(a) {
            return a = a.replace(/((^[ \t]*>[ \t]?.+\n(.+\n)*\n*)+)/gm,
            function(a, c) {
                var b;
                b = c.replace(/^[ \t]*>[ \t]?/gm, "~0");
                b = b.replace(/~0/g, "");
                b = b.replace(/^[ \t]+$/gm, "");
                b = A(b);
                b = b.replace(/(^|\n)/g, "$1  ");
                b = b.replace(/(\s*<pre>[^\r]+?<\/pre>)/gm,
                function(a, c) {
                    var b;
                    b = c.replace(/^  /mg, "~0");
                    return b = b.replace(/~0/g, "")
                });
                return s("<blockquote>\n" + b + "\n</blockquote>")
            })
        }
        function b(a, c) {
            for (var a = a.replace(/^\n+/g, ""), a = a.replace(/\n+$/g, ""), b = a.split(/\n{2,}/g), d = [], g = /~K(\d+)K/, q = b.length, i = 0; i < q; i++) {
                var f = b[i];
                g.test(f) ? d.push(f) : /\S/.test(f) && (f = e(f), f = f.replace(/^([ \t]*)/g, "<p>"), f += "</p>", d.push(f))
            }
            if (!c) {
                q = d.length;
                for (i = 0; i < q; i++) for (var k = !0; k;) k = !1,
                d[i] = d[i].replace(/~K(\d+)K/g,
                function(a, c) {
                    k = !0;
                    return H[c]
                })
            }
            return d.join("\n\n")
        }
        function g(a) {
            a = a.replace(/&(?!#?[xX]?(?:[0-9a-fA-F]+|\w+);)/g, "&amp;");
            return a = a.replace(/<(?![a-z\/?\$!])/gi, "&lt;")
        }
        function k(a) {
            a = a.replace(/(^|\s)(https?|ftp)(:\/\/[-A-Z0-9+&@#\/%?=~_|\[\]\(\)!:,\.;]*[-A-Z0-9+&@#\/%=~_|\[\]])($|\W)/gi, "$1<$2$3>$4");
            return a = a.replace(/<((https?|ftp):[^'">\s]+)>/gi,
            function(a, c) {
                return '<a href="' + c + '">' + G.plainLinkText(c) + "</a>"
            })
        }
        function f(a) {
            return a = a.replace(/~E(\d+)E/g,
            function(a, c) {
                var b = parseInt(c);
                return String.fromCharCode(b)
            })
        }
        function u(a) {
            a = a.replace(/^(\t|[ ]{1,4})/gm, "~0");
            return a = a.replace(/~0/g, "")
        }
        function n(a) {
            if (!/\t/.test(a)) return a;
            var c = ["    ", "   ", "  ", " "],
            b = 0,
            d;
            return a.replace(/[\n\t]/g,
            function(a, g) {
                if (a === "\n") return b = g + 1,
                a;
                d = (g - b) % 4;
                b = g + 1;
                return c[d]
            })
        }
        function i(a) {
            if (!a) return "";
            var c = a.length;
            return a.replace(L,
            function(b, d) {
                if (b == "~D") return "%24";
                if (b == ":" && (d == c - 1 || /[0-9\/]/.test(a.charAt(d + 1)))) return ":";
                return "%" + b.charCodeAt(0).toString(16)
            })
        }
        function p(a, c, b) {
            c = "([" + c.replace(/([\[\]\\])/g, "\\$1") + "])";
            b && (c = "\\\\" + c);
            return a = a.replace(RegExp(c, "g"), l)
        }
        function l(a, c) {
            return "~E" + c.charCodeAt(0) + "E"
        }
        var G = this.hooks = new t;
        G.addNoop("plainLinkText");
        G.addNoop("preConversion");
        G.addNoop("postConversion");
        var q, D, H, I;
        this.makeHtml = function(a) {
            if (q) throw Error("Recursive call to converter.makeHtml");
            q = new o;
            D = new o;
            H = [];
            I = 0;
            a = G.preConversion(a);
            a = a.replace(/~/g, "~T");
            a = a.replace(/\$/g, "~D");
            a = a.replace(/\r\n/g, "\n");
            a = a.replace(/\r/g, "\n");
            a = n("\n\n" + a + "\n\n");
            a = a.replace(/^[ \t]+$/mg, "");
            a = v(a);
            a = j(a);
            a = A(a);
            a = f(a);
            a = a.replace(/~D/g, "$$");
            a = a.replace(/~T/g, "~");
            a = G.postConversion(a);
            H = D = q = null;
            return a
        };
        var K = {
            ol: "\\d+[.]",
            ul: "[*+-]"
        },
        L = /(?:["'*()[\]:]|~D)/g
    }
})(); (function() {
    function y(e) {
        return e.replace(/<[^>]*>?/gi, C)
    }
    function C(e) {
        return e.match(v) || e.match(z) || e.match(A) ? e: ""
    }
    function t(e) {
        if (e == "") return "";
        var j = /<\/?\w+[^>]*(\s|$|>)/g,
        o = e.toLowerCase().match(j),
        h = (o || []).length;
        if (h == 0) return e;
        for (var r, x, t, w = [], v = [], s = !1, a = 0; a < h; a++) if (r = o[a].replace(/<\/?(\w+).*/, "$1"), !(w[a] || "<p><img><br><li><hr>".search("<" + r + ">") > -1)) {
            x = o[a];
            t = -1;
            if (!/^<\//.test(x)) for (x = a + 1; x < h; x++) if (!w[x] && o[x] == "</" + r + ">") {
                t = x;
                break
            }
            t == -1 ? s = v[a] = !0 : w[t] = !0
        }
        if (!s) return e;
        a = 0;
        return e = e.replace(j,
        function(c) {
            c = v[a] ? "": c;
            a++;
            return c
        })
    }
    var o, j;
    typeof exports === "object" && typeof require === "function" ? (o = exports, j = require("./Markdown.Converter").Converter) : (o = window.Markdown, j = o.Converter);
    o.getSanitizingConverter = function() {
        var e = new j;
        e.hooks.chain("postConversion", y);
        e.hooks.chain("postConversion", t);
        return e
    };
    var v = /^(<\/?(b|blockquote|code|del|dd|dl|dt|em|h1|h2|h3|i|kbd|li|ol|p|pre|s|sup|sub|strong|strike|ul|table|tr|th|td)>|<(br|hr)\s?\/?>)$/i,
    z = /^(<a\shref="((https?|ftp):\/\/|\/)[-A-Za-z0-9+&@#\/%?=~_|!:,.;\(\)]+"(\stitle="[^"<>]+")?\s?>|<\/a>)$/i,
    A = /^(<img\ssrc="(https?:\/\/|\/)[-A-Za-z0-9+&@#\/%?=~_|!:,.;\(\)]+"(\swidth="\d{1,3}")?(\sheight="\d{1,3}")?(\salt="[^"<>]*")?(\stitle="[^"<>]*")?\s?\/?>)$/i
})(); (function() {
    function y() {}
    function C(a) {
        this.buttonBar = h.getElementById("wmd-button-bar" + a);
        this.preview = h.getElementById("wmd-preview" + a);
        this.input = h.getElementById("wmd-input" + a)
    }
    function t(a, c) {
        var d = this,
        b = [],
        g = 0,
        k = "none",
        f,
        h,
        n,
        i = function(a, c) {
            k != a && (k = a, c || l()); ! w.isIE || k != "moving" ? h = setTimeout(p, 1) : n = null
        },
        p = function(a) {
            n = new o(c, a);
            h = void 0
        };
        this.setCommandMode = function() {
            k = "command";
            l();
            h = setTimeout(p, 0)
        };
        this.canUndo = function() {
            return g > 1
        };
        this.canRedo = function() {
            if (b[g + 1]) return ! 0;
            return ! 1
        };
        this.undo = function() {
            d.canUndo() && (f ? (f.restore(), f = null) : (b[g] = new o(c), b[--g].restore(), a && a()));
            k = "none";
            c.input.focus();
            p()
        };
        this.redo = function() {
            d.canRedo() && (b[++g].restore(), a && a());
            k = "none";
            c.input.focus();
            p()
        };
        var l = function() {
            var d = n || new o(c);
            if (!d) return ! 1;
            k == "moving" ? f || (f = d) : (f && (b[g - 1].text != f.text && (b[g++] = f), f = null), b[g++] = d, b[g + 1] = null, a && a())
        },
        j = function(a) {
            var c = !1;
            if (a.ctrlKey || a.metaKey) switch (String.fromCharCode(a.charCode || a.keyCode)) {
            case "y":
                d.redo();
                c = !0;
                break;
            case "z":
                a.shiftKey ? d.redo() : d.undo(),
                c = !0
            }
            if (c && (a.preventDefault && a.preventDefault(), window.event)) window.event.returnValue = !1
        },
        q = function(a) {
            if (!a.ctrlKey && !a.metaKey) a = a.keyCode,
            a >= 33 && a <= 40 || a >= 63232 && a <= 63235 ? i("moving") : a == 8 || a == 46 || a == 127 ? i("deleting") : a == 13 ? i("newlines") : a == 27 ? i("escape") : (a < 16 || a > 20) && a != 91 && i("typing")
        }; (function() {
            e.addEvent(c.input, "keypress",
            function(a) { (a.ctrlKey || a.metaKey) && (a.keyCode == 89 || a.keyCode == 90) && a.preventDefault()
            });
            var a = function() {
                if ((w.isIE || n && n.text != c.input.value) && h == void 0) k = "paste",
                l(),
                p()
            };
            e.addEvent(c.input, "keydown", j);
            e.addEvent(c.input, "keydown", q);
            e.addEvent(c.input, "mousedown",
            function() {
                i("moving")
            });
            c.input.onpaste = a;
            c.input.ondrop = a
        })();
        p(!0);
        l()
    }
    function o(a, c) {
        var d = this,
        b = a.input;
        this.init = function() {
            if (e.isVisible(b) && (c || !(h.activeElement && h.activeElement !== b))) if (this.setInputAreaSelectionStartEnd(), this.scrollTop = b.scrollTop, !this.text && b.selectionStart || b.selectionStart === 0) this.text = b.value
        };
        this.setInputAreaSelection = function() {
            if (e.isVisible(b)) if (b.selectionStart !== void 0 && !w.isOpera) b.focus(),
            b.selectionStart = d.start,
            b.selectionEnd = d.end,
            b.scrollTop = d.scrollTop;
            else if (h.selection && !(h.activeElement && h.activeElement !== b)) {
                b.focus();
                var a = b.createTextRange();
                a.moveStart("character", -b.value.length);
                a.moveEnd("character", -b.value.length);
                a.moveEnd("character", d.end);
                a.moveStart("character", d.start);
                a.select()
            }
        };
        this.setInputAreaSelectionStartEnd = function() {
            if (!a.ieCachedRange && (b.selectionStart || b.selectionStart === 0)) d.start = b.selectionStart,
            d.end = b.selectionEnd;
            else if (h.selection) {
                d.text = e.fixEolChars(b.value);
                var c = a.ieCachedRange || h.selection.createRange(),
                k = e.fixEolChars(c.text),
                f = "\u0007" + k + "\u0007";
                c.text = f;
                var u = e.fixEolChars(b.value);
                c.moveStart("character", -f.length);
                c.text = k;
                d.start = u.indexOf("\u0007");
                d.end = u.lastIndexOf("\u0007") - 1;
                if (f = d.text.length - e.fixEolChars(b.value).length) {
                    for (c.moveStart("character", -k.length); f--;) k += "\n",
                    d.end += 1;
                    c.text = k
                }
                if (a.ieCachedRange) d.scrollTop = a.ieCachedScrollTop;
                a.ieCachedRange = null;
                this.setInputAreaSelection()
            }
        };
        this.restore = function() {
            if (d.text != void 0 && d.text != b.value) b.value = d.text;
            this.setInputAreaSelection();
            b.scrollTop = d.scrollTop
        };
        this.getChunks = function() {
            var a = new y;
            a.before = e.fixEolChars(d.text.substring(0, d.start));
            a.startTag = "";
            a.selection = e.fixEolChars(d.text.substring(d.start, d.end));
            a.endTag = "";
            a.after = e.fixEolChars(d.text.substring(d.end));
            a.scrollTop = d.scrollTop;
            return a
        };
        this.setChunks = function(a) {
            a.before += a.startTag;
            a.after = a.endTag + a.after;
            this.start = a.before.length;
            this.end = a.before.length + a.selection.length;
            this.text = a.before + a.selection + a.after;
            this.scrollTop = a.scrollTop
        };
        this.init()
    }
    function j(a, c, d) {
        var b, g, k, f = function() {
            var a = 0;
            if (window.innerHeight) a = window.pageYOffset;
            else if (h.documentElement && h.documentElement.scrollTop) a = h.documentElement.scrollTop;
            else if (h.body) a = h.body.scrollTop;
            return a
        },
        u = function() {
            if (c.preview) {
                var b = c.input.value;
                if (! (b && b == k)) {
                    k = b;
                    var d = (new Date).getTime(),
                    b = a.makeHtml(b);
                    g = (new Date).getTime() - d;
                    o(b)
                }
            }
        },
        n = function() {
            b && (clearTimeout(b), b = void 0);
            var a = 0,
            a = g;
            a > 3E3 && (a = 3E3);
            b = setTimeout(u, a)
        },
        i = function(a) {
            if (a.scrollHeight <= a.clientHeight) return 1;
            return a.scrollTop / (a.scrollHeight - a.clientHeight)
        };
        this.refresh = function(a) {
            a ? (k = "", u()) : n()
        };
        this.processingTime = function() {
            return g
        };
        var p = !0,
        l = function(a) {
            var b = c.preview,
            d = b.parentNode,
            q = b.nextSibling;
            d.removeChild(b);
            b.innerHTML = a;
            q ? d.insertBefore(b, q) : d.appendChild(b)
        },
        j = function(a) {
            c.preview.innerHTML = a
        },
        q,
        D = function(a) {
            if (q) return q(a);
            try {
                j(a),
                q = j
            } catch(c) {
                q = l,
                q(a)
            }
        },
        o = function(a) {
            var b = B.getTop(c.input) - f();
            c.preview && (D(a), d());
            if (c.preview) c.preview.scrollTop = (c.preview.scrollHeight - c.preview.clientHeight) * i(c.preview);
            if (p) p = !1;
            else {
                var q = B.getTop(c.input) - f();
                w.isIE ? setTimeout(function() {
                    window.scrollBy(0, q - b)
                },
                0) : window.scrollBy(0, q - b)
            }
        }; (function(a, c) {
            e.addEvent(a, "input", c);
            a.onpaste = c;
            a.ondrop = c;
            e.addEvent(a, "keypress", c);
            e.addEvent(a, "keydown", c)
        })(c.input, n);
        u();
        if (c.preview) c.preview.scrollTop = 0
    }
    function v(a, c, d, b, g, k) {
        function f(a) {
            p.focus();
            if (a.textOp) {
                d && d.setCommandMode();
                var g = new o(c);
                if (!g) return;
                var i = g.getChunks(),
                f = function() {
                    p.focus();
                    i && g.setChunks(i);
                    g.restore();
                    b.refresh()
                };
                a.textOp(i, f) || f()
            }
            a.execute && a.execute(d)
        }
        function u(a, b) {
            var d = a.getElementsByTagName("span")[0];
            if (b) {
                d.style.backgroundPosition = a.XShift + " 0px";
                a.onmouseover = function() {
                    d.style.backgroundPosition = this.XShift + " -40px"
                };
                a.onmouseout = function() {
                    d.style.backgroundPosition = this.XShift + " 0px"
                };
                if (w.isIE) a.onmousedown = function() {
                    if (! (h.activeElement && h.activeElement !== c.input)) c.ieCachedRange = document.selection.createRange(),
                    c.ieCachedScrollTop = c.input.scrollTop
                };
                if (!a.isHelp) a.onclick = function() {
                    if (this.onmouseout) this.onmouseout();
                    f(this);
                    return ! 1
                }
            } else d.style.backgroundPosition = a.XShift + " -20px",
            a.onmouseover = a.onmouseout = a.onclick = function() {}
        }
        function n(a) {
            typeof a === "string" && (a = g[a]);
            return function() {
                a.apply(g, arguments)
            }
        }
        function i() {
            d && (u(l.undo, d.canUndo()), u(l.redo, d.canRedo()))
        }
        var p = c.input,
        l = {}; (function() {
            var b = c.buttonBar,
            d = document.createElement("ul");
            d.id = "wmd-button-row" + a;
            d.className = "wmd-button-row";
            var d = b.appendChild(d),
            g = 0,
            b = function(b, c, f, i) {
                var e = document.createElement("li");
                e.className = "wmd-button";
                e.style.left = g + "px";
                g += 25;
                var k = document.createElement("span");
                e.id = b + a;
                e.appendChild(k);
                e.title = c;
                e.XShift = f;
                if (i) e.textOp = i;
                u(e, !0);
                d.appendChild(e);
                return e
            },
            f = function(b) {
                var c = document.createElement("li");
                c.className = "wmd-spacer wmd-spacer" + b;
                c.id = "wmd-spacer" + b + a;
                d.appendChild(c);
                g += 25
            };
            l.bold = b("wmd-bold-button", "\u7c97\u4f53 <strong> Ctrl+B", "0px", n("doBold"));
            l.italic = b("wmd-italic-button", "\u659c\u4f53 <em> Ctrl+I", "-20px", n("doItalic"));
            f(1);
            l.link = b("wmd-link-button", "\u8d85\u7ea7\u94fe\u63a5 <a> Ctrl+L", "-40px", n(function(a, b) {
                return this.doLinkOrImage(a, b, !1)
            }));
            l.quote = b("wmd-quote-button", "\u5f15\u7528\u6587\u5b57 <blockquote> Ctrl+Q", "-60px", n("doBlockquote"));
            l.code = b("wmd-code-button", "\u4ee3\u7801 <pre><code> Ctrl+K", "-80px", n("doCode"));
            l.image = b("wmd-image-button", "\u56fe\u7247 <img> Ctrl+G", "-100px", n(function(a, b) {
                return this.doLinkOrImage(a, b, !0)
            }));
            f(2);
            l.olist = b("wmd-olist-button", "\u7f16\u53f7 <ol> Ctrl+O", "-120px", n(function(a, b) {
                this.doList(a, b, !0)
            }));
            l.ulist = b("wmd-ulist-button", "\u9879\u76ee\u7b26\u53f7 <ul> Ctrl+U", "-140px", n(function(a, b) {
                this.doList(a, b, !1)
            }));
            l.heading = b("wmd-heading-button", "\u6807\u9898 <h1>/<h2> Ctrl+H", "-160px", n("doHeading"));
            l.hr = b("wmd-hr-button", "\u6c34\u5e73\u7ebf <hr> Ctrl+R", "-180px", n("doHorizontalRule"));
            f(3);
            l.undo = b("wmd-undo-button", "\u540e\u9000 - Ctrl+Z", "-200px", null);
            l.undo.execute = function(a) {
                a && a.undo()
            };
            f = /win/.test(x.platform.toLowerCase()) ? "\u524d\u8fdb - Ctrl+Y": "\u524d\u8fdb - Ctrl+Shift+Z";
            l.redo = b("wmd-redo-button", f, "-220px", null);
            l.redo.execute = function(a) {
                a && a.redo()
            };
            if (k) b = document.createElement("li"),
            f = document.createElement("span"),
            b.appendChild(f),
            b.className = "wmd-button wmd-help-button",
            b.id = "wmd-help-button" + a,
            b.XShift = "-240px",
            b.isHelp = !0,
            b.style.right = "0px",
            b.title = k.title || J,
            b.onclick = k.handler,
            u(b, !0),
            d.appendChild(b),
            l.help = b;
            i()
        })();
        var j = "keydown";
        w.isOpera && (j = "keypress");
        e.addEvent(p, j,
        function(a) {
            if ((a.ctrlKey || a.metaKey) && !a.altKey && !a.shiftKey) {
                switch (String.fromCharCode(a.charCode || a.keyCode).toLowerCase()) {
                case "b":
                    f(l.bold);
                    break;
                case "i":
                    f(l.italic);
                    break;
                case "l":
                    f(l.link);
                    break;
                case "q":
                    f(l.quote);
                    break;
                case "k":
                    f(l.code);
                    break;
                case "g":
                    f(l.image);
                    break;
                case "o":
                    f(l.olist);
                    break;
                case "u":
                    f(l.ulist);
                    break;
                case "h":
                    f(l.heading);
                    break;
                case "r":
                    f(l.hr);
                    break;
                case "y":
                    f(l.redo);
                    break;
                case "z":
                    a.shiftKey ? f(l.redo) : f(l.undo);
                    break;
                default:
                    return
                }
                a.preventDefault && a.preventDefault();
                if (window.event) window.event.returnValue = !1
            }
        });
        e.addEvent(p, "keyup",
        function(a) {
            if (a.shiftKey && !a.ctrlKey && !a.metaKey && (a.charCode || a.keyCode) === 13) a = {},
            a.textOp = n("doAutoindent"),
            f(a)
        });
        e.addEvent(p, j,
        function(a) {
            var b = a.charCode || a.keyCode;
            if (!a.ctrlKey && !a.metaKey && !a.altKey && b == 9) {
                b = {};
                b.textOp = a.shiftKey ? n("doAutoShiftTab") : n("doAutoTab");
                f(b);
                if (w.isIE) a.returnValue = !1;
                a.preventDefault && a.preventDefault()
            }
        });
        w.isIE && e.addEvent(p, "keydown",
        function(a) {
            if (a.keyCode === 27) return ! 1
        });
        this.setUndoRedoButtonStates = i
    }
    function z(a) {
        this.hooks = a
    }
    function A(a) {
        return a.replace(/^\s*(.*?)(?:\s+"(.+)")?\s*$/,
        function(a, d, b) {
            d = d.replace(/\?.*$/,
            function(a) {
                return a.replace(/\+/g, " ")
            });
            d = decodeURIComponent(d);
            d = encodeURI(d).replace(/'/g, "%27").replace(/\(/g, "%28").replace(/\)/g, "%29");
            d = d.replace(/\?.*$/,
            function(a) {
                return a.replace(/\+/g, "%2b")
            });
            b && (b = b.trim ? b.trim() : b.replace(/^\s*/, "").replace(/\s*$/, ""), b = b.replace(/"/g, "quot;").replace(/\(/g, "&#40;").replace(/\)/g, "&#41;").replace(/</g, "&lt;").replace(/>/g, "&gt;"));
            return b ? d + ' "' + b + '"': d
        })
    }
    var e = {},
    B = {},
    E = {},
    h = window.document,
    r = window.RegExp,
    x = window.navigator,
    F = {
        lineLength: 72
    },
    w = {
        isIE: /msie/.test(x.userAgent.toLowerCase()),
        isIE_5or6: /msie 6/.test(x.userAgent.toLowerCase()) || /msie 5/.test(x.userAgent.toLowerCase()),
        isOpera: /opera/.test(x.userAgent.toLowerCase())
    },
    J = "Markdown \u7f16\u8f91\u5668\u5e2e\u52a9";
    Markdown.Editor = function(a, c, d) {
        var c = c || "",
        b = this.hooks = new Markdown.HookCollection;
        b.addNoop("onPreviewRefresh");
        b.addNoop("postBlockquoteCreation");
        b.addFalse("insertImageDialog");
        this.getConverter = function() {
            return a
        };
        var g = this,
        e;
        this.run = function() {
            if (!e) {
                e = new C(c);
                var f = new z(b),
                u = new j(a, e,
                function() {
                    b.onPreviewRefresh()
                }),
                n,
                i;
                if (!/\?noundo/.test(h.location.href)) n = new t(function() {
                    u.refresh();
                    i && i.setUndoRedoButtonStates()
                },
                e),
                this.textOperation = function(a) {
                    n.setCommandMode();
                    a();
                    g.refreshPreview()
                };
                i = new v(c, e, n, u, f, d);
                i.setUndoRedoButtonStates(); (g.refreshPreview = function() {
                    u.refresh(!0)
                })()
            }
        }
    };
    y.prototype.findTags = function(a, c) {
        var d = this,
        b;
        if (a) b = e.extendRegExp(a, "", "$"),
        this.before = this.before.replace(b,
        function(a) {
            d.startTag += a;
            return ""
        }),
        b = e.extendRegExp(a, "^", ""),
        this.selection = this.selection.replace(b,
        function(a) {
            d.startTag += a;
            return ""
        });
        if (c) b = e.extendRegExp(c, "", "$"),
        this.selection = this.selection.replace(b,
        function(a) {
            d.endTag = a + d.endTag;
            return ""
        }),
        b = e.extendRegExp(c, "^", ""),
        this.after = this.after.replace(b,
        function(a) {
            d.endTag = a + d.endTag;
            return ""
        })
    };
    y.prototype.trimWhitespace = function(a) {
        var c, d = this;
        a ? a = c = "": (a = function(a) {
            d.before += a;
            return ""
        },
        c = function(a) {
            d.after = a + d.after;
            return ""
        });
        this.selection = this.selection.replace(/^(\s*)/, a).replace(/(\s*)$/, c)
    };
    y.prototype.skipLines = function(a, c, d) {
        a === void 0 && (a = 1);
        c === void 0 && (c = 1);
        a++;
        c++;
        var b, g;
        navigator.userAgent.match(/Chrome/) && "X".match(/()./);
        this.selection = this.selection.replace(/(^\n*)/, "");
        this.startTag += r.$1;
        this.selection = this.selection.replace(/(\n*$)/, "");
        this.endTag += r.$1;
        this.startTag = this.startTag.replace(/(^\n*)/, "");
        this.before += r.$1;
        this.endTag = this.endTag.replace(/(\n*$)/, "");
        this.after += r.$1;
        if (this.before) {
            for (b = g = ""; a--;) b += "\\n?",
            g += "\n";
            d && (b = "\\n*");
            this.before = this.before.replace(new r(b + "$", ""), g)
        }
        if (this.after) {
            for (b = g = ""; c--;) b += "\\n?",
            g += "\n";
            d && (b = "\\n*");
            this.after = this.after.replace(new r(b, ""), g)
        }
    };
    e.isVisible = function(a) {
        if (window.getComputedStyle) return window.getComputedStyle(a, null).getPropertyValue("display") !== "none";
        else if (a.currentStyle) return a.currentStyle.display !== "none"
    };
    e.addEvent = function(a, c, d) {
        a.attachEvent ? a.attachEvent("on" + c, d) : a.addEventListener(c, d, !1)
    };
    e.removeEvent = function(a, c, d) {
        a.detachEvent ? a.detachEvent("on" + c, d) : a.removeEventListener(c, d, !1)
    };
    e.fixEolChars = function(a) {
        a = a.replace(/\r\n/g, "\n");
        return a = a.replace(/\r/g, "\n")
    };
    e.extendRegExp = function(a, c, d) {
        if (c === null || c === void 0) c = "";
        if (d === null || d === void 0) d = "";
        var a = a.toString(),
        b,
        a = a.replace(/\/([gim]*)$/,
        function(a, c) {
            b = c;
            return ""
        }),
        a = a.replace(/(^\/|\/$)/g, "");
        return new r(c + a + d, b)
    };
    B.getTop = function(a, c) {
        var d = a.offsetTop;
        if (!c) for (; a = a.offsetParent;) d += a.offsetTop;
        return d
    };
    B.getHeight = function(a) {
        return a.offsetHeight || a.scrollHeight
    };
    B.getWidth = function(a) {
        return a.offsetWidth || a.scrollWidth
    };
    B.getPageSize = function() {
        var a, c, d, b;
        self.innerHeight && self.scrollMaxY ? (a = h.body.scrollWidth, c = self.innerHeight + self.scrollMaxY) : h.body.scrollHeight > h.body.offsetHeight ? (a = h.body.scrollWidth, c = h.body.scrollHeight) : (a = h.body.offsetWidth, c = h.body.offsetHeight);
        if (self.innerHeight) d = self.innerWidth,
        b = self.innerHeight;
        else if (h.documentElement && h.documentElement.clientHeight) d = h.documentElement.clientWidth,
        b = h.documentElement.clientHeight;
        else if (h.body) d = h.body.clientWidth,
        b = h.body.clientHeight;
        return [Math.max(a, d), Math.max(c, b), d, b]
    };
    E.createBackground = function() {
        var a = h.createElement("div"),
        c = a.style;
        a.className = "wmd-prompt-background";
        c.position = "absolute";
        c.top = "0";
        c.zIndex = "1000";
        w.isIE ? c.filter = "alpha(opacity=50)": c.opacity = "0.5";
        var d = B.getPageSize();
        c.height = d[1] + "px";
        c.left = "0";
        c.width = "100%";
        h.body.appendChild(a);
        return a
    };
    E.prompt = function(a, c, d) {
        var b, g;
        c === void 0 && (c = "");
        var k = function(a) { (a.charCode || a.keyCode) === 27 && f(!0)
        },
        f = function(a) {
            e.removeEvent(h.body, "keydown", k);
            var c = g.value;
            a ? c = null: (c = c.replace(/^http:\/\/(https?|ftp):\/\//, "$1://"), /^(?:https?|ftp):\/\//.test(c) || (c = "http://" + c));
            b.parentNode.removeChild(b);
            d(c);
            return ! 1
        },
        j = function() {
            b = h.createElement("div");
            b.className = "wmd-prompt-dialog";
            b.style.padding = "10px;";
            b.style.position = "fixed";
            b.style.width = "400px";
            b.style.zIndex = "1001";
            var d = h.createElement("div");
            d.innerHTML = a;
            d.style.padding = "5px";
            b.appendChild(d);
            var d = h.createElement("form"),
            i = d.style;
            d.onsubmit = function() {
                return f(!1)
            };
            i.padding = "0";
            i.margin = "0";
            i.cssFloat = "left";
            i.width = "100%";
            i.textAlign = "center";
            i.position = "relative";
            b.appendChild(d);
            g = h.createElement("input");
            g.type = "text";
            g.value = c;
            i = g.style;
            i.display = "block";
            i.width = "80%";
            i.marginLeft = i.marginRight = "auto";
            d.appendChild(g);
            var p = h.createElement("input");
            p.type = "button";
            p.onclick = function() {
                return f(!1)
            };
            p.value = "\u786e\u5b9a";
            i = p.style;
            i.margin = "10px";
            i.display = "inline";
            i.width = "7em";
            var l = h.createElement("input");
            l.type = "button";
            l.onclick = function() {
                return f(!0)
            };
            l.value = "\u53d6\u6d88";
            i = l.style;
            i.margin = "10px";
            i.display = "inline";
            i.width = "7em";
            d.appendChild(p);
            d.appendChild(l);
            e.addEvent(h.body, "keydown", k);
            b.style.top = "50%";
            b.style.left = "50%";
            b.style.display = "block";
            if (w.isIE_5or6) b.style.position = "absolute",
            b.style.top = h.documentElement.scrollTop + 200 + "px",
            b.style.left = "50%";
            h.body.appendChild(b);
            b.style.marginTop = -(B.getHeight(b) / 2) + "px";
            b.style.marginLeft = -(B.getWidth(b) / 2) + "px"
        };
        setTimeout(function() {
            j();
            var a = c.length;
            if (g.selectionStart !== void 0) g.selectionStart = 0,
            g.selectionEnd = a;
            else if (g.createTextRange) {
                var b = g.createTextRange();
                b.collapse(!1);
                b.moveStart("character", -a);
                b.moveEnd("character", a);
                b.select()
            }
            g.focus()
        },
        0)
    };
    var s = z.prototype;
    s.prefixes = "(?:\\s{4,}|\\s*>|\\s*-\\s+|\\s*\\d+\\.|=|\\+|-|_|\\*|#|\\s*\\[[^\n]]+\\]:)";
    s.unwrap = function(a) {
        var c = new r("([^\\n])\\n(?!(\\n|" + this.prefixes + "))", "g");
        a.selection = a.selection.replace(c, "$1 $2")
    };
    s.wrap = function(a, c) {
        this.unwrap(a);
        var d = new r("(.{1," + c + "})( +|$\\n?)", "gm"),
        b = this;
        a.selection = a.selection.replace(d,
        function(a, c) {
            if ((new r("^" + b.prefixes, "")).test(a)) return a;
            return c + "\n"
        });
        a.selection = a.selection.replace(/\s+$/, "")
    };
    s.doBold = function(a, c) {
        return this.doBorI(a, c, 2, "strong text")
    };
    s.doItalic = function(a, c) {
        return this.doBorI(a, c, 1, "emphasized text")
    };
    s.doBorI = function(a, c, d, b) {
        a.trimWhitespace();
        a.selection = a.selection.replace(/\n{2,}/g, "\n");
        var e = /(\**$)/.exec(a.before)[0],
        c = /(^\**)/.exec(a.after)[0],
        e = Math.min(e.length, c.length);
        if (e >= d && (e != 2 || d != 1)) a.before = a.before.replace(r("[*]{" + d + "}$", ""), ""),
        a.after = a.after.replace(r("^[*]{" + d + "}", ""), "");
        else if (!a.selection && c) a.after = a.after.replace(/^([*_]*)/, ""),
        a.before = a.before.replace(/(\s?)$/, ""),
        a.before = a.before + c + r.$1;
        else {
            if (!a.selection && !c) a.selection = b;
            d = d <= 1 ? "*": "**";
            a.before += d;
            a.after = d + a.after
        }
    };
    s.stripLinkDefs = function(a, c) {
        return a = a.replace(/^[ ]{0,3}\[(\d+)\]:[ \t]*\n?[ \t]*<?(\S+?)>?[ \t]*\n?[ \t]*(?:(\n*)["(](.+?)[")][ \t]*)?(?:\n+|$)/gm,
        function(a, b, e, k, f) {
            c[b] = a.replace(/\s*$/, "");
            if (k) return c[b] = a.replace(/["(](.+?)[")]$/, ""),
            k + f;
            return ""
        })
    };
    s.addLinkDef = function(a, c) {
        var d = 0,
        b = {};
        a.before = this.stripLinkDefs(a.before, b);
        a.selection = this.stripLinkDefs(a.selection, b);
        a.after = this.stripLinkDefs(a.after, b);
        var e = "",
        k = /(\[)((?:\[[^\]]*\]|[^\[\]])*)(\][ ]?(?:\n[ ]*)?\[)(\d+)(\])/g,
        f = function(a) {
            d++;
            a = a.replace(/^[ ]{0,3}\[(\d+)\]:/, "  [" + d + "]:");
            e += "\n" + a
        },
        h = function(a, c, e, g, n, j) {
            e = e.replace(k, h);
            if (b[n]) return f(b[n]),
            c + e + g + d + j;
            return a
        };
        a.before = a.before.replace(k, h);
        c ? f(c) : a.selection = a.selection.replace(k, h);
        var n = d;
        a.after = a.after.replace(k, h);
        if (a.after) a.after = a.after.replace(/\n*$/, "");
        if (!a.after) a.selection = a.selection.replace(/\n*$/, "");
        a.after += "\n\n" + e;
        return n
    };
    s.doLinkOrImage = function(a, c, d) {
        a.trimWhitespace();
        a.findTags(/\s*!?\[/, /\][ ]?(?:\n[ ]*)?(\[.*?\])?/);
        var b;
        if (a.endTag.length > 1 && a.startTag.length > 0) a.startTag = a.startTag.replace(/!?\[/, ""),
        a.endTag = "",
        this.addLinkDef(a, null);
        else if (a.selection = a.startTag + a.selection + a.endTag, a.startTag = a.endTag = "", /\n\n/.test(a.selection)) this.addLinkDef(a, null);
        else {
            var e = this,
            k = function(f) {
                b.parentNode.removeChild(b);
                if (f !== null && (a.selection = (" " + a.selection).replace(/([^\\](?:\\\\)*)(?=[[\]])/g, "$1\\").substr(1), f = " [999]: " + A(f), f = e.addLinkDef(a, f), a.startTag = d ? "![": "[", a.endTag = "][" + f + "]", !a.selection)) a.selection = d ? "\u5728\u6b64\u8f93\u5165\u56fe\u7247\u63cf\u8ff0": "\u5728\u6b64\u8f93\u5165\u94fe\u63a5\u63cf\u8ff0";
                c()
            };
            b = E.createBackground();
            d ? this.hooks.insertImageDialog(k) || E.prompt('<p><b>\u63d2\u5165\u56fe\u7247</b></p><p>http://example.com/images/diagram.jpg "optional title"<br></p>', "http://", k) : E.prompt('<p><b>\u63d2\u5165\u94fe\u63a5</b></p><p>http://example.com/ "optional title"</p>', "http://", k);
            return ! 0
        }
    };
    s.doAutoindent = function(a) {
        var c = !1;
        a.before = a.before.replace(/(\n|^)[ ]{0,3}([*+-]|\d+[.])[ \t]*\n$/, "\n\n");
        a.before = a.before.replace(/(\n|^)[ ]{0,3}>[ \t]*\n$/, "\n\n");
        a.before = a.before.replace(/(\n|^)[ \t]+\n$/, "\n\n");
        if (!a.selection && !/^[ \t]*(?:\n|$)/.test(a.after)) a.after = a.after.replace(/^[^\n]*/,
        function(c) {
            a.selection = c;
            return ""
        }),
        c = !0;
        /(\n|^)[ ]{0,3}([*+-]|\d+[.])[ \t]+.*\n$/.test(a.before) && this.doList && this.doList(a);
        /(\n|^)[ ]{0,3}>[ \t]+.*\n$/.test(a.before) && this.doBlockquote && this.doBlockquote(a);
        if (/(\n|^)(\t|[ ]{4,}).*\n$/.test(a.before) && this.doCode) a.startTag = "    ",
        a.selection = "\u5728\u6b64\u8f93\u5165\u4ee3\u7801";
        if (c) a.after = a.selection + a.after,
        a.selection = ""
    };
    s.doAutoTab = function(a) {
        var c = /\S[ ]*$/.test(a.before);
        if (!/^[ ]*\S/.test(a.after) && !c || /\n/.test(a.selection)) / \n / .test(a.selection) ? a.selection = a.selection.replace(/^/gm, "    ") : a.before += "    ";
        else if (a.startTag = "    ", a.selection) a.selection = ""
    };
    s.doAutoShiftTab = function(a) {
        if (a.selection) a.selection = a.selection.replace(/^[ ]{4}/gm, ""),
        a.before = a.before.replace(/[ ]{4}$/, "")
    };
    s.doBlockquote = function(a) {
        a.selection = a.selection.replace(/^(\n*)([^\r]+?)(\n*)$/,
        function(b, c, d, e) {
            a.before += c;
            a.after = e + a.after;
            return d
        });
        a.before = a.before.replace(/(>[ \t]*)$/,
        function(b, c) {
            a.selection = c + a.selection;
            return ""
        });
        a.selection = a.selection.replace(/^(\s|>)+$/, "");
        a.selection = a.selection || "\u5f15\u7528\u6587\u5b57";
        var c = "",
        d = "",
        b;
        if (a.before) {
            for (var e = a.before.replace(/\n$/, "").split("\n"), k = !1, f = 0; f < e.length; f++) {
                var h = !1;
                b = e[f];
                k = k && b.length > 0;
                /^>/.test(b) ? (h = !0, !k && b.length > 1 && (k = !0)) : h = /^[ \t]*$/.test(b) ? !0 : k;
                h ? c += b + "\n": (d += c + b, c = "\n")
            }
            /(^|\n)>/.test(c) || (d += c, c = "")
        }
        a.startTag = c;
        a.before = d;
        if (a.after) a.after = a.after.replace(/^\n?/, "\n");
        a.after = a.after.replace(/^(((\n|^)(\n[ \t]*)*>(.+\n)*.*)+(\n[ \t]*)*)/,
        function(b) {
            a.endTag = b;
            return ""
        });
        c = function(b) {
            var c = b ? "> ": "";
            if (a.startTag) a.startTag = a.startTag.replace(/\n((>|\s)*)\n$/,
            function(a, b) {
                return "\n" + b.replace(/^[ ]{0,3}>?[ \t]*$/gm, c) + "\n"
            });
            if (a.endTag) a.endTag = a.endTag.replace(/^\n((>|\s)*)\n/,
            function(a, b) {
                return "\n" + b.replace(/^[ ]{0,3}>?[ \t]*$/gm, c) + "\n"
            })
        };
        if (/^(?![ ]{0,3}>)/m.test(a.selection)) this.wrap(a, F.lineLength - 2),
        a.selection = a.selection.replace(/^/gm, "> "),
        c(!0),
        a.skipLines();
        else {
            a.selection = a.selection.replace(/^[ ]{0,3}> ?/gm, "");
            this.unwrap(a);
            c(!1);
            if (!/^(\n|^)[ ]{0,3}>/.test(a.selection) && a.startTag) a.startTag = a.startTag.replace(/\n{0,2}$/, "\n\n");
            if (!/(\n|^)[ ]{0,3}>.*$/.test(a.selection) && a.endTag) a.endTag = a.endTag.replace(/^\n{0,2}/, "\n\n")
        }
        a.selection = this.hooks.postBlockquoteCreation(a.selection);
        if (!/\n/.test(a.selection)) a.selection = a.selection.replace(/^(> *)/,
        function(b, c) {
            a.startTag += c;
            return ""
        })
    };
    s.doCode = function(a, c) {
        var d = /\S[ ]*$/.test(a.before),
        b = function(a) {
            var b = $('<div class="wmd-prompt-background" style="position: absolute; top: 0px; z-index: 1000; filter:alpha(opacity=50); opacity: 0.5; height: ' + $(document).height() + 'px; left: 0px; width: 100%; "></div>'),
            d = $('         \t\t\t<div style="top: 50%; left: 50%; display: block; position: fixed; width:400px; z-index:1001" class="wmd-prompt-dialog">         \t\t\t<p><strong>\u7a0b\u5e8f\u4ee3\u7801\u6216\u811a\u672c</strong></p>         \t\t\t<p style="margin:10px;">         \t\t\t<select id="ic_lang" name="lang"> \t                    <option value="">[\u9009\u62e9\u7f16\u7a0b\u8bed\u8a00]</option> \t                \t<option value="java">Java</option> \t            \t\t<option value="cpp">C/C++/Objective-C</option> \t            \t\t<option value="c#">C#</option> \t            \t\t<option value="js">JavaScript</option> \t            \t\t<option value="php">PHP</option> \t            \t\t<option value="perl">Perl</option> \t            \t\t<option value="python">Python</option> \t            \t\t<option value="ruby">Ruby</option> \t            \t\t<option value="html">HTML</option> \t            \t\t<option value="xml">XML</option> \t            \t\t<option value="css">CSS</option> \t            \t\t<option value="vb">ASP/Basic</option> \t            \t\t<option value="pascal">Delphi/Pascal</option> \t            \t\t<option value="scala">Scala</option> \t            \t\t<option value="groovy">Groovy</option> \t            \t\t<option value="lua">Lua</option> \t            \t\t<option value="sql">SQL</option> \t            \t\t<option value="cpp">Google Go</option> \t            \t\t<option value="as3">Flash/ActionScript/Flex</option> \t            \t\t<option value="xml">WPF/SliverLight</option> \t            \t\t<option value="shell">Shell/\u6279\u5904\u7406</option> \t            \t</select> \u4ee5\u4fbf\u7cfb\u7edf\u8fdb\u884c\u6b63\u786e\u7684\u8bed\u6cd5\u7740\u8272        \t\t\t</p>         \t\t\t<p id="dialog-message" style="padding-top: 10px; margin:0; line-height: 16px;display:none;"></p>         \t\t\t<div style="text-align: center; position: relative;">         \t\t\t<input type="button" value="\u786e\u5b9a" id="ok-image-button" style="width: 7em; margin:10px 0 10px 0;" />         \t        <input type="button" value="\u53d6\u6d88" class="close-dialog-button" style="width: 7em; margin:10px 0 10px 10px;" />         \t\t\t</div>         \t\t\t</div>        \t\t'),
            e = function() {
                $(document).unbind("keydown", g);
                d.remove();
                b.remove()
            },
            g = function(a) { (a.charCode || a.keyCode) === 27 && e()
            };
            setTimeout(function() {
                b.appendTo("body");
                d.appendTo("body");
                d.css({
                    "margin-top": -(d.height() / 2) + "px",
                    "margin-left": -(d.width() / 2) + "px"
                });
                $(document).keydown(g);
                $(".close-dialog-button").click(function() {
                    e()
                });
                $("#ok-image-button").click(function() {
                    var b = $("#ic_lang").val();
                    b == "" ? $("#dialog-message").css({
                        color: "red",
                        "font-weight": "bold"
                    }).show().text("\u8bf7\u9009\u62e9\u7f16\u7a0b\u8bed\u8a00\uff01") : (a(b), e(), c())
                })
            },
            0)
        };
        if (!/^[ ]*\S/.test(a.after) && !d || /\n/.test(a.selection)) {
            a.before = a.before.replace(/[ ]{4}$/,
            function(b) {
                a.selection = b + a.selection;
                return ""
            });
            var e = d = 1;
            /(\n|^)(\t|[ ]{4,}).*\n$/.test(a.before) && (d = 0);
            /^\n(\t|[ ]{4,})/.test(a.after) && (e = 0);
            a.skipLines(d, e);
            a.selection ? /^[ ]{0,3}\S/m.test(a.selection) ? b(function(b) {
                b = "```" + b + " \n    ";
            a.endTag="\n```";
                /\n/.test(a.selection) ? a.selection = a.selection.replace(/^/gm, b) : a.before += b
            }) : a.selection = a.selection.replace(/^[ ]{4}/gm, "") : b(function(b) {
                a.startTag = "```" + b + " \n    ";
                a.selection = "\u5728\u6b64\u8f93\u5165\u4ee3\u7801";
                a.endTag="\n```";
            })
        } else if (a.trimWhitespace(), a.findTags(/`/, /`/), !a.startTag && !a.endTag) {
            if (a.startTag = a.endTag = "`", !a.selection) a.selection = "\u5728\u6b64\u8f93\u5165\u4ee3\u7801"
        } else a.endTag && !a.startTag ? (a.before += a.endTag, a.endTag = "") : a.startTag = a.endTag = ""
    };
    s.doList = function(a, c, d) {
        var c = /^\n*(([ ]{0,3}([*+-]|\d+[.])[ \t]+.*)(\n.+|\n{2,}([*+-].*|\d+[.])[ \t]+.*|\n{2,}[ \t]+\S.*)*)\n*/,
        b = "-",
        e = 1,
        h = function() {
            var a;
            d ? (a = " " + e + ". ", e++) : a = " " + b + " ";
            return a
        },
        f = function(a) {
            d === void 0 && (d = /^\s*\d/.test(a));
            return a = a.replace(/^[ ]{0,3}([*+-]|\d+[.])\s/gm,
            function() {
                return h()
            })
        };
        a.findTags(/(\n|^)*[ ]{0,3}([*+-]|\d+[.])\s+/, null);
        if (a.before && !/\n$/.test(a.before) && !/^\n/.test(a.startTag)) a.before += a.startTag,
        a.startTag = "";
        if (a.startTag) {
            var j = /\d+[.]/.test(a.startTag);
            a.startTag = "";
            a.selection = a.selection.replace(/\n[ ]{4}/g, "\n");
            this.unwrap(a);
            a.skipLines();
            if (j) a.after = a.after.replace(c, f);
            if (d == j) return
        }
        var n = 1;
        a.before = a.before.replace(/(\n|^)(([ ]{0,3}([*+-]|\d+[.])[ \t]+.*)(\n.+|\n{2,}([*+-].*|\d+[.])[ \t]+.*|\n{2,}[ \t]+\S.*)*)\n*$/,
        function(a) {
            if (/^\s*([*+-])/.test(a)) b = r.$1;
            n = /[^\n]\n\n[^\n]/.test(a) ? 1 : 0;
            return f(a)
        });
        if (!a.selection) a.selection = "\u5217\u8868";
        var j = h(),
        i = 1;
        a.after = a.after.replace(c,
        function(a) {
            i = /[^\n]\n\n[^\n]/.test(a) ? 1 : 0;
            return f(a)
        });
        a.trimWhitespace(!0);
        a.skipLines(n, i, !0);
        a.startTag = j;
        c = j.replace(/./g, " ");
        this.wrap(a, F.lineLength - c.length);
        a.selection = a.selection.replace(/\n/g, "\n" + c)
    };
    s.doHeading = function(a) {
        a.selection = a.selection.replace(/\s+/g, " ");
        a.selection = a.selection.replace(/(^\s+|\s+$)/g, "");
        if (a.selection) {
            var c = 0;
            a.findTags(/#+[ ]*/, /[ ]*#+/);
            if (/#+/.test(a.startTag)) c = r.lastMatch.length;
            a.startTag = a.endTag = "";
            a.findTags(null, /\s?(-+|=+)/);
            /=+/.test(a.endTag) && (c = 1);
            /-+/.test(a.endTag) && (c = 2);
            a.startTag = a.endTag = "";
            a.skipLines(1, 1);
            c = c == 0 ? 2 : c - 1;
            if (c > 0) {
                var c = c >= 2 ? "-": "=",
                d = a.selection.length;
                if (d > F.lineLength) d = F.lineLength;
                for (a.endTag = "\n"; d--;) a.endTag += c
            }
        } else a.startTag = "## ",
        a.selection = "\u6807\u9898",
        a.endTag = " ##"
    };
    s.doHorizontalRule = function(a) {
        a.startTag = "----------\n";
        a.selection = "";
        a.skipLines(2, 1, !0)
    }
})();
function doInsertImage(y) {
    var C = "upload-iframe-" + (new Date).getTime(),
    t = $(' \t<div style="top: 50%; left: 50%; display: block; position: fixed; width:400px; z-index:1001" class="wmd-prompt-dialog">        <div style="padding: 10px;"> \t   <p><b>\u63d2\u5165\u56fe\u7247</b></p>        <p id="tab_switcher" style="padding-top: 10px;"><a href="javascript:;" class="wmd-mini-button selected" id="switch-image-url">\u7f51\u7edc\u56fe\u7247</a><a href="javascript:;" class="wmd-mini-button" id="switch-upload-image">\u672c\u5730\u4e0a\u4f20</a></p>        </div> \t   <div id="tabUrl" style="text-align: center; position: relative;"> \t     <div style="position: relative;"><input type="text" name="imageurl" id="imageurl-input" value="http://" style="width:80%; margin:auto;" /></div> \t\t <p style="padding-top: 10px; margin:0; line-height: 16px;">\u7c98\u8d34\u6216\u8f93\u5165\u7f51\u7edc\u56fe\u7247\u5730\u5740</p> \t\t <input type="button" value="\u786e\u5b9a" id="image-url-button" style="width: 7em; margin:10px 0 10px 0;" />          <input type="button" value="\u53d6\u6d88" class="close-dialog-button" style="width: 7em; margin: 10px 0 10px 10px;" /> \t   </div> \t   <div id="tabFile" style="text-align: center; position: relative; display:none;"> \t   <iframe id="' + C + '" style="display:none;" src="about:blank" name="' + C + '"></iframe>        <form action="user/wmd_upload_img" method="post" enctype="multipart/form-data">         <input type="file" name="imgFile" id="filename-input" style="width:80%; margin:auto;" />         <p id="upload-message" style="padding-top: 10px; margin:0; line-height: 16px;">\u6d4f\u89c8\u5e76\u9009\u62e9\u672c\u5730\u6587\u4ef6</p>         <div class="ac_loading" id="image-upload-progress" style="background-color: transparent; display:none;">\u6b63\u5728\u4e0a\u4f20 ...</div> \t    <input type="submit" value="\u4e0a\u4f20" id="upload-image-button" style="width: 7em;margin:10px 0 10px 0;" />         <input type="button" value="\u53d6\u6d88" class="close-dialog-button" style="width: 7em; margin: 10px 0 10px 10px;" />        </form> \t   </div> \t</div> \t'),
    o = t.find("form"),
    j = t.find("iframe"),
    v = function(e) {
        $(document).unbind("keydown", z);
        j.unbind("load");
        o.unbind("submit");
        $("#imageurl-input").val("http://");
        y(e);
        t.remove()
    },
    z = function(e) { (e.charCode || e.keyCode) === 27 && v(null)
    },
    A = function(e) {
        $("#image-upload-progress").hide();
        $("#upload-message").css({
            color: "red",
            "font-weight": "bold"
        }).show().text(e)
    };
    setTimeout(function() {
        t.appendTo("body");
        t.css({
            "margin-top": -(t.height() / 2) + "px",
            "margin-left": -(t.width() / 2) + "px"
        });
        $(document).keydown(z);
        $(".close-dialog-button").click(function() {
            v(null)
        });
        $("#tab_switcher a").click(function() {
            $("#tabUrl").toggle();
            $("#tabFile").toggle();
            $("#switch-image-url").toggleClass("selected");
            $("#switch-upload-image").toggleClass("selected")
        });
        $("#image-url-button").click(function() {
            var e = $("#imageurl-input").val();
            e.length == 0 ? ($("#imageurl-input").focus(), alert("\u8bf7\u8f93\u5165\u56fe\u7247URL\uff01")) : (/^(?:https?|ftp):\/\//.test(e) || (e = "http://" + e), v(e))
        });
        o.submit(function() {
            if ($("#filename-input").val().length == 0) return alert("\u8bf7\u9009\u62e9\u6587\u4ef6\uff01"),
            $("#filename-input").focus(),
            !1;
            $("#upload-message").hide();
            $("#image-upload-progress").show();
            this.target = C;
            j.bind("load",
            function() {
                o[0].reset();
                var e = (this.contentDocument || this.contentWindow.document).body.innerHTML;
                if (e == void 0 || e.length == 0) A("\u4e0a\u4f20\u5931\u8d25\uff01");
                else {
                    var j;
                    try {
                        j = eval("(" + e + ")")
                    } catch(t) {
                        A(e);
                        return
                    }
                    j && (j.error == 0 ? (A("\u4e0a\u4f20\u6210\u529f\uff01"), v(j.url)) : A(j.message))
                }
            });
            return ! 0
        })
    },
    0);
    return ! 0
}
function showHelp() {
    window.open("http://wowubuntu.com/markdown/")
};